﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Import Namespace="Buffalo.Administration.DAL" %>
<%@ Import Namespace="Buffalo.Administration.Enum" %>
<%@ Import Namespace="Buffalo.SMECommon.DAL" %>
<%@ Import Namespace="Buffalo.SMECommon.Enum" %>
<%@ Import Namespace="Buffalo.Web.Areas.SMECommon" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title></title>
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                //bool hasEditPermission = new PermissionDAL().HasPermission(GeneralVar.gLoggedUserName, "OrderType", enuPermissionType.Edit);
                //btnSave.Visible = hasEditPermission;
                ///btnAdd.Visible = btnSave.Visible;

                //hidHasEditPermission.Value = hasEditPermission;
            }
            Buffalo.Web.Areas.SMECommon.GeneralVar.gLanguageHelper.ApplyLanguage(this.viewPortOrderType, Buffalo.Web.Areas.SMECommon.CommonManager.GetCurrentCulture(), true);
        }
    </script>
    <script type="text/javascript">
        var commandHandler = function (cmd, record) {
            switch (cmd) {
                case "delete":
                    if (hidHasEditPermission.getValue() != "true")
                        return;
                    Ext.Msg.confirm('Alert', 'Delete OrderType?', function (btn) {
                        if (btn == "yes") {
                            dsOrderType.remove(record);
                            dsOrderType.save();
                        }
                    });
                    break;
            }
        };
    </script>
</head>
<body>
    <ext:ResourceManager ID="ResourceManager1" runat="server" />
    <ext:Store ID="dsOrderType" runat="server" RemoteSort="true" UseIdConfirmation="false" AutoLoad="false">
        <Proxy>
            <ext:HttpProxy Url="/SMECommon/Catalog/GetListOrderType/" />
        </Proxy>
        <UpdateProxy>
            <ext:HttpWriteProxy Url="/SMECommon/Catalog/SaveOrderTypes/" />
        </UpdateProxy>
        <Reader>
            <ext:JsonReader IDProperty="ID" Root="data" TotalProperty="total">
                <Fields>
                    <ext:RecordField Name="ID" />
                    <ext:RecordField Name="SortNo" />
                    <ext:RecordField Name="Code" />
                    <ext:RecordField Name="Name" />
                    <ext:RecordField Name="Note" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <BaseParams>
            <ext:Parameter Name="limit" Value="15" Mode="Raw" />
            <ext:Parameter Name="start" Value="0" Mode="Raw" />
            <ext:Parameter Name="dir" Value="ASC" />
            <ext:Parameter Name="sort" Value="Name" />
            <ext:Parameter Name="withDefaultItem" Value="false"  Mode="Value"/> 
            <ext:Parameter Name="cboCriteria" Value="#{cboCriteria}.getValue()" Mode="Raw" />
            <ext:Parameter Name="txtSearchText" Value="#{txtSearchText}.getValue()" Mode="Raw" />
        </BaseParams>
        <SortInfo Field="Name" Direction="ASC" />
    </ext:Store>

    <ext:Viewport ID="viewPortOrderType" runat="server" Layout="fit">
        <Items>
            <ext:GridPanel ID="GridPanel1" runat="server" Header="false" Border="false" TrackMouseOver="true"
                AutoExpandColumn="Note" StoreID="dsOrderType">
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:CommandColumn Width="25" Hideable="false">
                            <Commands>
                                <ext:GridCommand CommandName="delete" Icon="Cross">
                                    <ToolTip Text="Delete" />
                                </ext:GridCommand>
                            </Commands>
                            <PrepareToolbar Handler="toolbar.setVisible(!record.newRecord);" />
                        </ext:CommandColumn>
                        <ext:Column ColumnID="Code" DataIndex="Code" Header="Code">
                            <Editor>
                                <ext:TextField ID="TextField3" runat="server" AllowBlank="false" />
                            </Editor>
                        </ext:Column>
                        <ext:Column ColumnID="Name" DataIndex="Name" Header="Name">
                            <Editor>
                                <ext:TextField ID="TextField1" runat="server" AllowBlank="false" />
                            </Editor>
                        </ext:Column>
                        <ext:Column ColumnID="Note" DataIndex="Note" Header="Note">
                            <Editor>
                                <ext:TextField ID="TextField2" runat="server" AllowBlank="false" />
                            </Editor>
                        </ext:Column>
                    </Columns>
                </ColumnModel>
                <TopBar>
                    <ext:Toolbar ID="mainToolbar" runat="server">
                        <Items>
                            <ext:Button ID="btnSave" runat="server" Text="Save" Icon="Disk">
                                <Listeners>
                                    <Click Handler="#{dsOrderType}.save();" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="btnAdd" runat="server" Text="Add" Icon="Add">
                                <Listeners>
                                    <Click Handler="#{GridPanel1}.insertRecord(0, {});#{GridPanel1}.getView().focusRow(0);#{GridPanel1}.startEditing(0, 0);" />
                                </Listeners>
                            </ext:Button>
                            <ext:ToolbarFill ID="ToolbarFill1" runat="server" />
                            <ext:SelectBox ID="cboCriteria" runat="server" EmptyText="Select criteria...">
                                <Items>
                                    <ext:ListItem Text="..." Value="ALL" />
                                    <ext:ListItem Text="Code" Value="Code" />
                                    <ext:ListItem Text="Name" Value="Name" />
                                    <ext:ListItem Text="Note" Value="Note" />
                                </Items>
                            </ext:SelectBox>
                            <ext:ToolbarSpacer ID="ToolbarSpacer2" runat="server" />
                            <ext:TextField ID="txtSearchText" runat="server" AnchorHorizontal="100%" EmptyText="Search..." />
                            <ext:ToolbarSpacer ID="ToolbarSpacer3" runat="server" />
                            <ext:Button ID="btnSearch" runat="server" Text="Search" Icon="Find">
                                <Listeners>
                                    <Click Handler="dsOrderType.reload();" />
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
                </SelectionModel>
                <BottomBar>
                    <ext:PagingToolbar ID="PagingToolbar1" runat="server" PageSize="15" />
                </BottomBar>
                <Listeners>
                    <Command Fn="commandHandler" />
                    <BeforeEdit Handler="return !(e.field=='ID' && !e.record.newRecord);" />
                </Listeners>
                <LoadMask ShowMask="true" />
                <SaveMask ShowMask="true" />
            </ext:GridPanel>
            <ext:Hidden ID="hidHasEditPermission" runat="server"></ext:Hidden>
        </Items>
    </ext:Viewport>
</body>
</html>
